package StackAndQueue;

import java.util.ArrayDeque;

public class MyQueue232 {
    public static void main(String[] args) {
        MyQueue232 queue = new MyQueue232();
        queue.push(1);
        queue.push(2);
        System.out.println(queue.peek());
        System.out.println(queue.pop());
        System.out.println(queue.empty());
    }

    ArrayDeque<Integer> stackIn = null;
    ArrayDeque<Integer> stackOut = null;
    public MyQueue232() {
        stackIn = new ArrayDeque<>();
        stackOut = new ArrayDeque<>();
    }

    public void push(int x) {
        stackIn.push(x);
    }

    public int pop() {
        transfer();
       return stackOut.pop();
    }

    public int peek() {
        transfer();
        return stackOut.peek();
    }

    public boolean empty() {
        return stackIn.isEmpty() && stackOut.isEmpty();
    }

    public void transfer(){
//        if (!stackOut.isEmpty()) return;
        if(stackOut.size() != 0){
            return;
        }
        while (stackIn.size() != 0){
            stackOut.push(stackIn.pop());
        }
    }
}
